<?php
class ModelSettingExtension extends Model {
	public function getInstalled($type, $restaurant_id = 0) {
		$extension_data = array();

		if($restaurant_id == 0) {
			$restaurant_id = $this->restaurant->getRestaurantId() == null? '0' : $this->restaurant->getRestaurantId();
		}
		
		$sql = "SELECT * FROM " . DB_PREFIX . "extension WHERE `type` = '" . $this->db->escape($type) . "'";
		$sql .= " AND `restaurant_id` = '" . $restaurant_id . "'";

		$query = $this->db->query($sql);

		foreach ($query->rows as $result) {
			$extension_data[] = $result['code'];
		}

		return $extension_data;
	}

	public function install($type, $code, $restaurant_id = 0) {
		if($restaurant_id == 0) {
			$restaurant_id = $this->restaurant->getRestaurantId() == null? '0' : $this->restaurant->getRestaurantId();
		}
				
		$sql = "INSERT INTO " . DB_PREFIX . "extension SET `type` = '" . $this->db->escape($type) . "', `code` = '" . $this->db->escape($code) . "'";
		$sql .= ", `restaurant_id` = '" . $this->db->escape($restaurant_id) . "'";

		$this->db->query($sql);
	}

	public function uninstall($type, $code, $restaurant_id = 0) {
		if($restaurant_id == 0) {
			$restaurant_id = $this->restaurant->getRestaurantId() == null? '0' : $this->restaurant->getRestaurantId();
		}
		
		$sql = "DELETE FROM " . DB_PREFIX . "extension WHERE `type` = '" . $this->db->escape($type) . "' AND `code` = '" . $this->db->escape($code) . "'";
		$sql .= " AND `restaurant_id` = '" . $restaurant_id . "'";

		$this->db->query($sql);
	}
}
?>